
#include "sample_isp.h"
#include "sample_vout.h"
#include "sample_vin.h"
#include "sample_osd_vo.h"
#include "sample_venc.h"
#include "sample_venc_osd.h"

extern int g_save_h264_file_flag;

typedef enum __osd_test_mode
{
    OSD_VENC_FREETYPE = 1,
    OSD_VENC_LATTICE =2,
    OSD_VO = 3,
    OSD_VO_VENC_FREETYPE = 4,
    OSD_VO_VENC_LATTICE = 5,
    OSD_NONE = 6,
} osd_test_mode_e;

struct inputparam
{
    int argc;
    char argv[20][100];
};

int main(int argc, char *argv[])
{
    int ret = SGKS_SUCCESS;
    int i=0;
    struct inputparam inputparam;
    osd_test_mode_e osdTestMode = OSD_NONE;

    memset(&inputparam, 0x00, sizeof(inputparam));
    inputparam.argc = argc;
    for(i = 0; i < inputparam.argc; i++)
    {
        strcpy(&inputparam.argv[i][0], argv[i]);
    }

    if(strcmp(&inputparam.argv[1][0], "vo") == 0)
    {
        osdTestMode = OSD_VO;
        if(strcmp(&inputparam.argv[2][0], "enc") == 0)
        {
            if(strcmp(&inputparam.argv[3][0], "0") == 0)
            {
                osdTestMode = OSD_VO_VENC_FREETYPE;
            }

            else if(strcmp(&inputparam.argv[3][0], "1") == 0)
            {
                osdTestMode = OSD_VO_VENC_LATTICE;
            }
            else
            {
                osdTestMode = OSD_NONE;
            }
        }
    }

    if(strcmp(&inputparam.argv[1][0], "enc") == 0)
    {
        if(strcmp(&inputparam.argv[2][0], "0") == 0)
        {
            osdTestMode = OSD_VENC_FREETYPE;
        }

        else if(strcmp(&inputparam.argv[2][0], "1") == 0)
        {
            osdTestMode = OSD_VENC_LATTICE;
        }
        else
        {
            osdTestMode = OSD_NONE;
        }
    }

    if(osdTestMode == OSD_NONE)
    {
        DEBUGMSG(ZONE_ERROR, ("Please input test params:\n"));
        DEBUGMSG(ZONE_ERROR, ("./sample-osd vo -->vout osd display\n"));
        DEBUGMSG(ZONE_ERROR, ("./sample-osd enc 0 -->venc osd(freetype font)\n"));
        DEBUGMSG(ZONE_ERROR, ("./sample-osd enc 1 -->venc osd(lattice font)\n"));
        DEBUGMSG(ZONE_ERROR, ("./sample-osd vo enc 0 -->vout osd display and venc osd(freetype font)\n"));
        DEBUGMSG(ZONE_ERROR, ("./sample-osd vo enc 1 -->vout osd display and venc osd(lattice font)\n"));
        return SGKS_SUCCESS;
    }

    ret = sgks_mpi_sample_SysInit(SGKS_DSP_ENCODE_MODE);
    if (ret != SGKS_SUCCESS)
        return ret;

    ret = sgks_mpi_sample_VinInit();
    if (ret != SGKS_SUCCESS)
        return ret;

    ret = sgks_mpi_sample_IspInit();
    if (ret != SGKS_SUCCESS)
        return ret;

    ret = sgks_mpi_sample_VoutInit(SGKS_VO_SRC_ENC, SGKS_VO_SRC_ENC);
    if (ret != SGKS_SUCCESS)
        return ret;

    ret =  sgks_mpi_sample_venc_setting(SENSOR_DATA_ENCODE_TEST);
    if (ret != SGKS_SUCCESS)
        return ret;

    ret =  sgks_mpi_sys_Start();
    if (ret != SGKS_SUCCESS)
        return ret;

    if(osdTestMode >= OSD_VO)
    {  	
        ret = Osd_VoTest();
        if (ret != SGKS_SUCCESS)
            return ret;
        
        if(osdTestMode == OSD_VO)
        {
            goto NEXT;
        }       
    }

    g_save_h264_file_flag = 1;
    ret = sgks_mpi_sample_venc_start();
    if (ret != SGKS_SUCCESS)
        return ret;

    if( osdTestMode == OSD_VENC_FREETYPE || osdTestMode == OSD_VO_VENC_FREETYPE)
    {
        ret = sgks_mpi_sample_venc_osd_start(OSD_FONT_FREETYPE_TYPE);
        if (ret != SGKS_SUCCESS)
            return ret;
    }

    if(osdTestMode == OSD_VENC_LATTICE || osdTestMode == OSD_VO_VENC_LATTICE)
    {
        ret = sgks_mpi_sample_venc_osd_start(OSD_FONT_LATTICE_TYPE);
        if (ret != SGKS_SUCCESS)
            return ret;
    }

    ret = sgks_mpi_sample_venc_test(SENSOR_DATA_ENCODE_TEST);
    if (ret != SGKS_SUCCESS)
        return ret;

NEXT:
    while(1)
    {
        sleep(1);
    }
    return SGKS_SUCCESS;
}
